package model;

import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;

public class Base {
	
	
	public static RecordStore openRecordStore(String nomeRecordStore) {
		RecordStore recordStore;
		try {
			recordStore = RecordStore.openRecordStore(nomeRecordStore, false);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
		return recordStore;
	}

	public static RecordStore openRecordStore(String nomeRecordStore,
			boolean criar) {
		
		RecordStore recordStore;
		
		try {
			recordStore = RecordStore.openRecordStore(nomeRecordStore, criar);
		} catch (Exception e) {
			
			e.printStackTrace();
			return null;
		}
		return recordStore;
	}

	public static boolean closeRecordStore(RecordStore recordStore) {
		try {
			recordStore.closeRecordStore();
		} catch (RecordStoreNotOpenException e) {
			e.printStackTrace();
			return false;
		} catch (RecordStoreException e) {
			e.printStackTrace();
			return false;
		}

		return true;
	}

	public static boolean deleteRecordStore(String nomeRecordStore) {
		try {
			RecordStore.deleteRecordStore(nomeRecordStore);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}